package com.zb.network.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.SelectVo;
import com.zb.network.service.ConNetworkTypeService;
import com.zb.result.Result;
import com.zb.service.ZjNetworkTypeService;
import com.zb.utils.TokenUtil;
import com.zb.vo.NetworkTypeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 服务商类型表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-09-11
 */
@Api(tags = "服务商类型接口")
@RestController
@RequestMapping("/network/type")
public class ZjNetworkTypeController {
    @Resource
    private ZjNetworkTypeService networkTypeService;
    @Resource
    private ConNetworkTypeService conNetworkTypeService;

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "服务区域-服务商设置-服务商类型 - 新增或修改服务商类型")
    @ApiOperation("新增或修改服务商类型")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid NetworkTypeVo networkTypeVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        networkTypeService.save(custAccId, networkTypeVo);
        return Result.success(null == networkTypeVo.getId()? "新增类型成功" : "修改类型成功");
    }

    @ApiOperation("获取服务商类型列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取服务商类型列表成功").data(networkTypeService.getList(custAccId, selectVo));
    }

    @ApiOperation("根据类型ID获取服务商类型详情")
    @PostMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "类型ID", required = true) Long id) {
        return Result.success("获取服务商类型详情成功").data("row", networkTypeService.getDetail(id));
    }

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.UPDATE, remark = "服务区域-服务商设置-服务商类型 - 批量启用或禁用类型")
    @ApiOperation("批量启用或禁用类型")
    @PutMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "类型状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "类型ID集合", required = true) List<Long> idList) {
        networkTypeService.updateDisabledBatchById(idList, status);
        return Result.success(status? "禁用类型成功" : "启用类型成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.UPDATE, remark = "服务区域-服务商设置-服务商类型 - 根据类型ID批量删除类型")
    @ApiOperation("根据类型ID批量删除类型")
    @DeleteMapping("/delete")
    public Result delete(@RequestBody @ApiParam(value = "类型ID集合", required = true) List<Long> idList) {
        conNetworkTypeService.deleteNetworkType(idList);
        return Result.success("删除类型成功");
    }
}
